package com.ss.user.controller;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.ss.user.pojo.Authority;
import com.ss.user.pojo.Role;
import com.ss.user.service.impl.AuthorityServiceImpl;

/**
 * 功能管理Controller
 *
 */
@Controller("authorityController")
@RequestMapping("/authority")
public class AuthorityController {
	
	@Autowired
	private AuthorityServiceImpl authorityService;
	/**
	 * 进入查询页面
	 * @param request
	 * @param response
	 * @param info
	 * @return
	 * @throws Exception
	 * 
	 */
	@RequestMapping("/initAuthority.do")
	public ModelAndView toPage(HttpServletRequest request,
			HttpServletResponse response,Role roleInfo) throws Exception {		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		roleInfo.init(request);
		resultMap.put("pageResult", roleInfo.pageResult);
		return new ModelAndView("system/authority",resultMap);		
	}
	/**
	 * 分页查询
	 * @param request
	 * @param response
	 * @param info
	 * @return
	 * @throws Exception
	 * 
	 */
	@RequestMapping("/queryAuthority.do")
	public ModelAndView searchAuthorityManage(HttpServletRequest request,
			HttpServletResponse response,Authority authorityInfo) throws Exception {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		authorityInfo.init(request);
		authorityService.queryAuthority(authorityInfo);
		resultMap.put("pageResult", authorityInfo.pageResult);
		return new ModelAndView("system/authority",resultMap);		
	}

	/**
	 * 新增功能
	 * @param request
	 * @param response
	 * @param authorityInfo
	 * @return
	 * @throws Exception
	 * 
	 */
	@RequestMapping("/addAuthority.do")
	public ModelAndView addAuthorityManage(HttpServletRequest request,
			HttpServletResponse response,Authority authorityInfo) throws Exception {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		authorityInfo.init(request);
		authorityInfo.setStatus("0");
		authorityService.addAuthority(authorityInfo);
		resultMap.put("pageResult", "success");
		return new ModelAndView("system/authority_add",resultMap);		
	}
	
	/**
	 * 更新功能
	 * @param request
	 * @param response
	 * @param authorityInfo
	 * @return
	 * @throws Exception
	 * 
	 */
	@RequestMapping("/updateAuthority.do")
	public ModelAndView updateAuthorityManage(HttpServletRequest request,
			HttpServletResponse response,Authority authorityInfo) throws Exception {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		authorityInfo.init(request);
		authorityService.updateAuthority(authorityInfo);
		resultMap.put("pageResult", "success");
		return new ModelAndView("system/authority_edit",resultMap);		
	}
	
	/**
	 * 更新功能初始化界面
	 * @param request
	 * @param response
	 * @param authorityInfo
	 * @return
	 * @throws Exception
	 * 
	 */
	@RequestMapping("/updateAuthorityInit.do")
	public ModelAndView updateAuthorityInit(HttpServletRequest request,
			HttpServletResponse response,Authority authorityInfo) throws Exception {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		authorityInfo.init(request);
		String id = request.getParameter("id");
		Authority returnInfo = authorityService.queryAuthorityById(id);
		resultMap.put("returnInfo", returnInfo);
		return new ModelAndView("system/authority_edit",resultMap);		
	}
}
